package com.nostop.controller;

import com.nostop.common.ApplicationContextHelper;
import com.nostop.common.JsonData;
import com.nostop.exception.ParamException;
import com.nostop.mapper.SysAclModuleMapper;
import com.nostop.model.SysAclModule;
import com.nostop.param.TestVo;
import com.nostop.util.BeanValidator;
import com.nostop.util.JsonMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/test")
@Slf4j
public class TestController {

    @RequestMapping("/hello.json")
    @ResponseBody
    public JsonData hello(){
        log.error("hello");
        throw new RuntimeException("test exception");
        //return JsonData.success("hello");
    }


    @RequestMapping("/validate.json")
    @ResponseBody
    public JsonData validate(TestVo vo) throws ParamException {
        log.error("validate");
        SysAclModuleMapper moduleMapper = ApplicationContextHelper.popBean(SysAclModuleMapper.class);
        SysAclModule mo = moduleMapper.selectByPrimaryKey(1);
        log.info("JsonMapper:"+JsonMapper.obj2String(mo));
        BeanValidator.checkParam(vo);
        return JsonData.success("  test  validate");
    }

}
